﻿{include file="/public/header" /}
<div class="content-wraper full">
    <div class="tools-bar">
        <a data-key="add"><i class="fa fa-plus"></i> 添加</a>
        <a data-key="edit"><i class="fa fa-edit"></i> 编辑</a>
        <a data-key="lock"><i class="fa fa-lock"></i> 锁定</a>
        <a data-key="unlock"><i class="fa fa-unlock-alt"></i> 解锁</a>
        <a data-key="depart"><i class="fa fa-unlink"></i> 离职</a>
    </div>

    <div class="normal-line"></div>
    <div class="search_wraper" style="min-height: 51px;">
        <form class="normal_form search_form" onsubmit="return false;">
            <div class="condition" onscroll="Core.scrolling(this)">
            </div>
            <div class="row form-footer-bar">
                <button class="btn" type="reset" role="btn-cancel">重置</button>
                <button r-button class="btn btn-primary search-btn" type="submit" role="btn-submit">搜索</button>
                <button r-button style="display: none;" class="btn switch_search filter">展开搜索条件<i class="fa fa-angle-down"></i></button>
                <div style="margin: 10px 0 -10px;"><a class="search_close"><i class="fa fa-angle-up"></i>收起</a></div>
            </div>
        </form>
    </div>
    <div class="table_box">
        <table class="table_main" id="datalist"></table>
    </div>
</div>
<script type="text/javascript">
Core.Easyui.FieldColumn = [
    {field:'ck',checkbox:true,width:30},
	{field:'realname',title:'姓名',width:120,align:'center',search: true, nowsearch: true, searchtype: 'input'},
    {field:'mobile',title:'手机号',width:120,align:'center',search: true, nowsearch: true, searchtype: 'input'},
    {field:'groupname',title:'角色',width:180,align:'center',formatter:function(value,row,index){
		return '<span style="'+(row.isadmin ? 'color:red' : '')+'">'+value+'</span>';//row.isadmin
	}},
    {field:'gender',title:'性别',width:100,align:'center',formatter:function(value,row,index){
		return ['','男','女'][value] || '';
	}},
    {field:'locked',title:'状态',width:80,align:'center',formatter:function(value,row,index){
		return ['正常','<span style="color:red">锁定</span>','<span style="color:red">离职</span>'][value] || '';
	}},
    {field:'-',title:'',align:'center'},
];

Core.Easyui.init($("#datalist"), {
    url: "{$_G['_mc_']}/ajax",
    idField: "uid",
    fitColumns: true,
    singleSelect : true,
    columns: [Core.Easyui.FieldColumn],
    pageSize: 50,
    onDblClickRow: function (index,row){
        Core.Sys.Action('pop',row);
    },
},$(".search_form"));


Core.Sys.Action = function(Tkey,row){
    switch(Tkey){
        case 'add':
            Core.Dialog.open({'title': '添加','width': '580px','height': '320px','url': "{$_G['_mc_'] ?? ''}/add"});
        break;
        case 'edit':
            var row = $('#datalist').datagrid('getSelected');
            if (!row) {
                Core.Dialog.msg('请选择需要操作的账户');return;
            }
            Core.Sys.Action('pop',row);
        break;
        case 'pop':
            if (!row || !row.suid) return;
            Core.Dialog.open({'title': '编辑','width': '580px','height': '320px','url': "{$_G['_mc_'] ?? ''}/edit/suid/"+row.suid});
        break;
        case 'unlock':case 'lock':
            var row = $('#datalist').datagrid('getSelected');
            if (!row) {
                Core.Dialog.msg('请选择需要操作的账户');return;
            } else if ((row.isadmin || 0)) {
                Core.Dialog.msg('单位管理员账户不可操作');return;
            }
            var p = {'unlock' : {'t' : '您确定要解锁该账户吗？解锁后将正常使用系统','v' : 1},'lock' : {'t' : '您确定要锁定该账户吗？锁定后将无法使用系统','v' : 2}}
            Core.Dialog.confirm({'title': '提示信息','content': p[Tkey].t || '','ok': function (cbk) {
                    $.getJSON("{$_G['_mc_'] ?? ''}/lock/p/"+(p[Tkey].v || '0')+"?suid="+row.suid+"&r="+Math.random(),function(data){
                        if(data.state != 'y'){
                            Core.Dialog.msg('操作失败，'+data.msg);
                        } else {
                            Core.Dialog.msg('操作成功');
                            $('#datalist').datagrid('reload');
                            cbk();
                        }
                    });
                },
            });
        break;
        case 'depart':
            var row = $('#datalist').datagrid('getSelected');
            if (!row) {
                Core.Dialog.msg('请选择需要操作的账户');return;
            } else if ((row.isadmin || 0)) {
                Core.Dialog.msg('单位管理员账户不可操作');return;
            }
            Core.Dialog.confirm({'title': '提示信息','content': '您确定该账户人员离职吗？离职后将无法使用系统','ok': function (cbk) {
                    $.getJSON("{$_G['_mc_'] ?? ''}/depart?suid="+row.suid+"&r="+Math.random(),function(data){
                        if(data.state != 'y'){
                            Core.Dialog.msg('操作失败，'+data.msg);
                        } else {
                            Core.Dialog.msg('操作成功');
                            $('#datalist').datagrid('reload');
                            cbk();
                        }
                    });
                },
            });
        break;
    }
    return;//unordertonet
}
$(document).ready(function(){
    $('.tools-bar').find('a[data-key]').on('click',function(){
        var Tkey = $(this).attr('data-key');
        if (!Core.rule('key',Tkey)) return false;
        Core.Sys.Action(Tkey);
    });
});

/**搜索 */
var Table_Filters = Core.Search.searchArray();
var filterType = Core.Search.typeList();
Core.Search.initFilter(null, null, null);

</script>
{include file="/public/footer" /}